package com.example.practice.controller;

import com.example.practice.entity.User;
import com.example.practice.entity.respMsg;
import com.example.practice.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/login")
@Api(tags = "LoginController")
public class LoginController {
    @Resource
    UserService userService;
    @ApiOperation("登录")
    @PostMapping("/login")
    public respMsg login(User user){
        if(this.userService.login(user)==400){
            return new respMsg(0,"没有找到用户",null,0);
        }
        else if(this.userService.login(user)==500){
            return new respMsg(0,"密码错误",null,0);
        }
        else {
        Integer login = this.userService.login(user);
        return new respMsg(0,"登录成功",login,0);
    }
    }
}
